﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.ServiceModel;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Status;

namespace Kiss.Mobile
{
    public partial class MainForm : Form
    {
        private bool online = true; // SystemState.ConnectionsCount > 0;

        public MainForm()
        {
            InitializeComponent();
        }

        private void doneMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void getMenuItem_Click(object sender, EventArgs e)
        {
            Customer[] customers;
            if(online)
            {
                OrderServiceClient.EndpointAddress = new EndpointAddress("http://192.168.0.100:2222/OrderService.svc");
                OrderServiceClient service = new OrderServiceClient();
                customers = service.GetCustomersByCity(cityTextBox.Text);
            }
            else
            {
                OrderHandler data = new OrderHandler();
                customers = data.GetCustomersByCity(cityTextBox.Text);
            }
            dataGrid.DataSource = customers;
        }

        private void updateMenuItem_Click(object sender, EventArgs e)
        {
            Customer customer = ((Customer[])dataGrid.DataSource)[0];
            if(!customer.City.EndsWith("X"))
                customer.City = customer.City + "X";
            else
                customer.City = customer.City.Remove(customer.City.Length - 1, 1);

            if(online)
            {
                OrderServiceClient service = new OrderServiceClient();
                service.UpdateCustomer(customer);
            }
            else
            {
                OrderHandler data = new OrderHandler();
                data.UpdateCustomer(customer);
            }
        }
    }
}